/**
 Svetlana Matusova, May 2009
 **/

package viewcomponents
{
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import mx.containers.Canvas;
	import mx.containers.HBox;
	import mx.containers.VBox;
	
	import viewcomponents.registration.RegistrationPanel;

	public class Dashboard extends Canvas
	{
		private var vbox:VBox = new VBox();
		private var hbox:HBox = new HBox();
		private var leftVbox:VBox = new VBox();
		private var rightVbox:VBox = new VBox();
		
		private var banner:Banner;
		//menu + menu buttons
		private var menu:MenuPanel;
		private var registrationButton:MenuButton;
		private var editButton:MenuButton;
		private var rankingButton:MenuButton;
		private var createGameButton:MenuButton;
		private var registeredGameButton:MenuButton;
		//login panel
		private var login:LoginPanel;
		private var dashboard:DashboardPanel;
		private var registration:RegistrationPanel;
		
		private var isRegistration:Boolean = false;
		
		public function Dashboard()
		{
			super();
 			vbox.percentWidth = 100;
			vbox.percentHeight = 100;
			addChild(vbox);
			
			banner = new Banner();
			banner.percentWidth = 100;
			banner.percentHeight = 15;			
			vbox.addChild(banner);
			
			menu = new MenuPanel(new Array());
			menu.percentWidth = 100;
			menu.percentHeight = 5;
			registrationButton = new MenuButton("Registration");
			registrationButton.percentWidth = 20;
			menu.addButton(registrationButton);
			registrationButton.addEventListener(MouseEvent.CLICK, registratonClick);
			addEventListener(Event.CHANGE, changeMenu);
			vbox.addChild(menu);
			
			hbox.percentWidth = 100;
			hbox.percentHeight = 80;
			vbox.addChild(hbox);
			
			leftVbox.percentHeight = 100;
			leftVbox.percentWidth = 20;
			login = new LoginPanel();
			login.percentHeight = 30;
			leftVbox.addChild(login);
			hbox.addChild(leftVbox);
			
			dashboard = new DashboardPanel();
			dashboard.percentHeight = 100;
			dashboard.percentWidth = 60;
			hbox.addChild(dashboard);
			
			rightVbox.percentHeight = 100;
			rightVbox.percentWidth = 20;
			hbox.addChild(rightVbox);
			
			registration = new RegistrationPanel();
			registration.percentHeight = 100;
			registration.percentWidth = 60;
			
		}
		
		
		//change menu after submit
		public function changeMenu(event:Event):void{
			menu.removeButton(registrationButton);
			
			editButton = new MenuButton("Edit Profile");
			editButton.percentWidth = 20;
			menu.addButton(editButton);
			
			rankingButton = new MenuButton("Ranking List");
			rankingButton.percentWidth = 20;
			menu.addButton(rankingButton);
			
			createGameButton = new MenuButton("Create Game");
			createGameButton.percentWidth = 20;
			menu.addButton(createGameButton);
			
			rankingButton = new MenuButton("Registrated Games");
			rankingButton.percentWidth = 20;
			menu.addButton(rankingButton);
			
			hbox.removeChildAt(1);
			hbox.addChildAt(dashboard, 1);
			
		}
		
		public function registratonClick(event:MouseEvent):void{
			if(!isRegistration){
				hbox.removeChildAt(1);
				hbox.addChildAt(registration, 1);
				isRegistration = true;
				
			}else{
				hbox.removeChildAt(1);
				hbox.addChildAt(dashboard, 1);
				isRegistration = false;
			}
		}
		
	}
}